<!--  Ofri Keidar 302933981 group 05 -->

<%@page import="controller.CustomerController"%>
<%@page import="model.database.DBException"%>
<%@page import="view.WebCommons"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<link rel="stylesheet" href="../../style/myTemplate/style.css"
	type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Get product price</title>
</head>
<body>

	<span class="customHeader2">Product's price</span>
		
<!-- 		get product's name -->
		
	<div id="page">
		<div class="post">

			<div id="sidebar">
				<ul>
					<li>
						<h2>Please enter product's name</h2>
					</li>
				</ul>
			</div>
		
			<div id="content">
				<form METHOD=POST ACTION="GetProductPrice.jsp">
					<table>
						<tr>
							<td><INPUT TYPE=TEXT NAME=name SIZE=<%=WebCommons.NAME_SIZE%>></td>
							<td><INPUT TYPE=SUBMIT VALUE="Go!" class="mySubmitButton"></td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</div>

	<%
		// get main menu page
		String menuPage = (String) session.getAttribute(WebCommons.MAIN_MANU);
	%>
	<div id="footer">
		<span class="myLink"><A HREF="<%="../../menus/" + menuPage%>">Back to Menu</A></span>
	</div>

	<%
		// check if already submitted product name
		if (!(request.getParameter("name") == null 
				|| request.getParameter("name").equals(""))) {

			// extract name
			String name = request.getParameter("name");

			try {

				// extract controller from session
				CustomerController controller = (CustomerController) session.getAttribute(WebCommons.CONTROLLER);

				// try getting product price
				double price = controller.getProductPrice(name);

				// check success
				if (Double.isNaN(price)) {

					// diplsay error message
					%>
					<span class="notify"><br>Sorry, could not get price- no product with the name "<%=name%>"</span>
					<%
					
				} else {

					// display price
					%>
					<span class="notify"><br><%=name%>'s price is <%=price%></span>
					<%
				}

			} catch (DBException e) {
				
				// move to error page
				response.sendRedirect("../../commonPages/ErrorPage.jsp");
			}
		}
	%>

</body>
</html>